package it.allerj.common.utility.executable;
import it.allerj.common.persistence.HibernateUtilities;

import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;



public class DbManager extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Launch the application
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			DbManager frame = new DbManager();
			frame.pack();
			frame.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the frame
	 */
	public DbManager() {
		super();
		setBounds(100, 100, 500, 375);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel panel = new JPanel();
		panel.setLayout(new GridBagLayout());
		final JButton button = new JButton();
		button.setFont(new Font("Times New Roman", Font.BOLD, (int)(this.getSize().height/5)));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				try {
					System.out.println(HibernateUtilities.generateSchema(false,true,true));
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		button.setText("Crea DB");
		final GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.fill = GridBagConstraints.BOTH;
		gridBagConstraints.weighty = 1;
		gridBagConstraints.weightx = 1;
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 0;

		
		
		panel.add(button, gridBagConstraints);
		
		final JButton button2 = new JButton();
		button2.setFont(new Font("Times New Roman", Font.BOLD, (int)(this.getSize().height/5)));
		button2.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				try {
					System.out.println(HibernateUtilities.generateSchema(false,true,false));
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		button2.setText("Aggiorna DB");

		final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
		gridBagConstraints_1.fill = GridBagConstraints.BOTH;
		gridBagConstraints_1.weighty = 1;
		gridBagConstraints_1.weightx = 1;
		gridBagConstraints_1.gridx = 0;
		gridBagConstraints_1.gridy = 1;

		panel.add(button2, gridBagConstraints_1);
		getContentPane().add(panel);
		
		
		

		
	}

}
